package com.hhf.feiojjudgeservice.strategy.impl;

import com.hhf.feiojcommonservice.model.dto.JudgeInfo;
import com.hhf.feiojjudgeservice.model.enums.JudgeInfoMessageEnum;
import com.hhf.feiojjudgeservice.strategy.JudgeStrategy;

import lombok.extern.slf4j.Slf4j;

/**
 * @Author hhf
 * @Date 2024/10/28
 * @Description
 */
@Slf4j
public class DefaultJudgeStrategy implements JudgeStrategy {
    @Override
    public JudgeInfo getJudgeInfo(JudgeInfo runJudgeInfo, JudgeInfo needJudgeInfo) {
        log.info("使用默认判题策略");
        // 题目限制
        Long needMemory = needJudgeInfo.getMemory();
        Long needTime = needJudgeInfo.getTime();
        // 实际执行结果
        Long runMemory = runJudgeInfo.getMemory();
        Long runTime = runJudgeInfo.getTime();
        String runMessage = runJudgeInfo.getMessage();

        //构造响应对象
        JudgeInfo response = new JudgeInfo();
        response.setMemory(runMemory);
        response.setTime(runTime);
        response.setMessage(runMessage);

        if (runMessage != JudgeInfoMessageEnum.ACCEPTED.getValue()){
            return response;
        }

        //根据题目限制与实际执行结果获取message
        if (needMemory > runMemory){
            response.setMessage(JudgeInfoMessageEnum.MEMORY_LIMIT_EXCEEDED.getValue());
        }
        if (needTime > runTime){
            response.setMessage(JudgeInfoMessageEnum.TIME_LIMIT_EXCEEDED.getValue());
        }
        //返回结果
        return response;
    }
}
